<?php
class BaseAction extends Action {
	public function _initialize() {
		//检查是否已登录
		$this->gotoLogin();
		
		//判断登录用户角色
		if(!($this->whoCanOperate('user')))$this->error('请以用户身份登录，才可以进行该操作！');
		
		//用户中心，基本功能对应数据 
		$userNavDict['Index'] = array(	'index'=>'欢迎 '.$this->user['uname']
										,'sendList'=>'送出的礼物'
										,'receiveList'=>'收到的礼物'
										,'tobesendList'=>'收藏的礼物'
										,'desirousList'=>'想要的礼物'
							);
		$userNavDict['Account'] = array('profile'=>'个人资料'
										,'security'=>'安全设置'
										,'namecard'=>'名片管理'
										//,'credit'=>'我的积分'
										,'cash'=>'现金账户'
										,'phonebook'=>'电&nbsp;话&nbsp;&nbsp;薄'
							);
		$this->assign('userNavDict', $userNavDict);
	}
	
	//检查Email是否可用
	public function isEmailAvailable($email = null) {
		$return_type = empty($email) ? 'ajax' 		   : 'return';
		$email		 = empty($email) ? $_POST['email'] : $email;
		
		$res = M('user')->where('`email`="'.$email.'"')->find();
		
		if ( !$res ) {
			if ($return_type === 'ajax') echo 'success';
			else return true;
		}else {
			if ($return_type === 'ajax') echo '邮箱已注册';
			else return false;
		}
	}
}